﻿using SSHTool.ViewModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SSHTool
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            Init();
        }

        private void Init()
        {
            MainViewModel vm = App.GetService<MainViewModel>();

            DataContext = vm;
            vm.Load();

            InitializeComponent();
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            if (DataContext is MainViewModel vm)
            {
                if (vm.ShutDownApp)
                {
                    base.OnClosing(e);
                }
                else
                {
                    Hide();

                    e.Cancel = true;
                }
            }
        }
    }
}
